﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Dynamic;
using System.Web.Mvc;
using GWEB.WebBase.Entity;
using GWEB.WebBase.Utility;
using GWEB.WebFrame.Public;
using Newtonsoft.Json;

namespace GWEB.WebFrame.Course
{
    public class BaseCourseDetailListController : PageInfoBase
    {
        [ActionFilter(IsLogin = false)]
        public ActionResult Index(String Id, String KeyCode)
        {
            ViewBag.Id = Id;
            ViewBag.KeyCode = KeyCode;
            return View(BasePage.V("Course/BaseCourseDetailList"));
        }

        [ActionFilter(IsLogin = false)]
        [HttpPost]
        public JsonResult ClassInfo(String CourseName, String ClassId, String id, String vid, String keyCode)//课程信息
        {
            if (!Fun.IDVerify(vid, keyCode))
                return BasePage.Json(ResultData.Code("0001", "您没有权限"));
            String sql = @"SELECT *  FROM cu_Course where 1=1";
            if (!string.IsNullOrEmpty(CourseName))
            {
                sql += "and CourseName LIKE '%" + CourseName + "%'";
            }
            if (!string.IsNullOrEmpty(ClassId))
            {
                sql += "and ClassId = " + ClassId + "";
            }
            if (!string.IsNullOrEmpty(id))
            {
                sql += "and id = " + id + "";
            }
            BasePage.bd.ColumnNameToLower = false;
            DataTable dt = BasePage.bd.ExecuteTable(sql);
            String str = JsonConvert.SerializeObject(dt);
            BasePage.bd.ColumnNameToLower = true;
            List<Dictionary<String, Object>> data = JsonConvert.DeserializeObject<List<Dictionary<String, Object>>>(str);
            return BasePage.Json(ResultData.OK(data));
        }
        [ActionFilter(IsLogin = false)]
        [HttpPost]
        public JsonResult DelClass(String id, String vid, String keyCode)//删除课程
        {
            if (!Fun.IDVerify(vid, keyCode))
                return BasePage.Json(ResultData.Code("0001", "您没有权限"));
            String sql = @"delete  FROM cu_Course where 1=1";
            if (!string.IsNullOrEmpty(id))
            {
                sql += "and id = " + id + "";
            }
            BasePage.bd.ColumnNameToLower = false;
            DataTable dt = BasePage.bd.ExecuteTable(sql);
            String str = JsonConvert.SerializeObject(dt);
            BasePage.bd.ColumnNameToLower = true;
            List<Dictionary<String, Object>> data = JsonConvert.DeserializeObject<List<Dictionary<String, Object>>>(str);
            return BasePage.Json(ResultData.OK(data));
        }

        protected override void FieldAddInit(DataRow data)
        {
            data["CreateId"] = BasePage.GetUserId(Session);
            DataRow drUser = BasePage.GetUser(Session);
            data["LeagueId"] = Fun.cString(drUser["LeagueId"].ToString());
            ViewBag.Lx = 0;
            base.FieldAddInit(data);
        }
        protected override void FieldEditInit(DataRow data)
        {
            ViewBag.Lx = 1;
            base.FieldEditInit(data);
        }
    }
}

